//
//  MyWebView.m
//  日夜间(范阳)
//
//  Created by dllo on 15/11/3.
//  Copyright © 2015年 dllo. All rights reserved.
//

#import "MyWebView.h"

@implementation MyWebView
-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame: frame];
    if (self) {
        [self webViewDidFinishLoad:self];
        [self delegate];
    }
    return self;
}
-(void)webViewDidFinishLoad:(UIWebView *)webView{
    //字体大小
    //    [webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust= '330%'"];
    //字体颜色
    if ([ThemeManage shareThemeManage].isNight) {
        
        [self stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('body')[0].style.webkitTextFillColor= 'white'"];
        [self stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('body')[0].style.backgroundColor= '#AAAAAA'"];
    }
    else
    {
        
        [self stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('body')[0].style.webkitTextFillColor= 'black'"];
        [self stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('body')[0].style.backgroundColor= '#FFFFFF'"];
    }
    //页面背景色
    //        [webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('body')[0].style.background='#2E2E2E'"];
    //------------------------------------------------------------
//    //修改JS语言
//    //定义JS字符串(JavaScript)
//    NSString *script = [NSString stringWithFormat:@"var script = document.createElement('script');"
//                        "script.type = 'text/javascript';"
//                        "script.text = \"function ResizeImages() { "
//                        "var myimg;"
//                        "var maxwidth = %d;"//屏幕宽度
//                        "for (i = 0; i < document.images.length; i++) {"
//                        "myimg = document.images[i];"
//                        "myimg.height = maxwidth / (myimg.width / myimg.height);"
//                        "myimg.width = maxwidth;"
//                        "}"
//                        "}\";"
//                        "document.getElementsByTagName('p')[0].appendChild(script);", 355];
//    //添加JS
//    [webView stringByEvaluatingJavaScriptFromString:script];
//    //添加调用JS执行的语句
//    [webView stringByEvaluatingJavaScriptFromString:@"ResizeImages();"];
//    //------------------------------------------------------------
}

@end
